//用户相关接口
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:part_time_job_pro/common/base/base_model.dart';
import 'package:part_time_job_pro/common/index.dart';
import 'package:part_time_job_pro/main.dart';

mixin UserMixin {
  ///用户短信登录
  Future<LoginUser?> smsCodeLogin(String mobile, String smsCode) async {
    if (mobile.isBlank) {
      EasyLoading.showToast("手机号码不能为空！");
      return null;
    }

    if (smsCode.isBlank) {
      EasyLoading.showToast("短信验证码不能为空！");
      return null;
    }

    var result = await restClient.smsCodeLogin(mobile, smsCode);
    return result?.data;
  }

  ///用户密码登录
  Future<LoginUser?> accountLogin(String account, String password) async {
    if (account.isBlank) {
      EasyLoading.showToast("登录账号不能为空!");
      return null;
    }
    if (password.isBlank) {
      EasyLoading.showToast("密码不能为空!");
      return null;
    }

    var result = await restClient.accountLogin(account, password);
    return result?.data;
  }

  //获取短信验证码
  Future<BaseModel?> sendSmsCode(String mobile) async {
    if (mobile.isBlank) {
      EasyLoading.showToast("手机号码不能为空！");
      return null;
    }
    var result = await restClient.sendSmsCode(mobile, "1");
    return result;
  }

  //用户退出登录
  Future<BaseModel?> userLoginOut() async {
    var result = await restClient.userLoginOut();
    return result;
  }
}
